package com.example.demo6.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;

import com.baomidou.mybatisplus.core.injector.methods.DeleteById;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.example.demo6.dao.StudentDao;
import com.example.demo6.pojo.Student;
import com.example.demo6.service.StudentService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

@Service
public class StudentServiceImpl implements StudentService {
    @Resource
    private StudentDao studentDao;

    @Override
    public Page<Student> findAll(Integer pageIndex, Student student) {
        LambdaQueryWrapper<Student> lambdaQueryWrapper = new LambdaQueryWrapper<>();
        lambdaQueryWrapper.like(student.getName()!=null,Student::getName,student.getName());
        return studentDao.selectPage(new Page<Student>(pageIndex,2),lambdaQueryWrapper);
    }

    @Override
    public void add(Student student) {
        studentDao.insert(student);
    }

    @Override
    public Student findById(Integer id) {
        return studentDao.selectById(id);
    }

    @Override
    public void edit(Student student) {
    studentDao.updateById(student);
    }

    @Override
    public void del(Integer id) {
        studentDao.deleteById(id);
    }
}
